package leetcode.code2000;

import leetcode.IDebug;

//执行用时：1 ms, 在所有 Java 提交中击败了27.67%的用户
//
//内存消耗：39.7 MB, 在所有 Java 提交中击败了5.16%的用户
//
//通过测试用例：112 / 112
public class Solution implements IDebug {

	public String reversePrefix(String word, char ch) {
		int pos = 0;
		while (pos < word.length()) {
			char c = word.charAt(pos);
			if (c == ch) {
				break;
			}
			pos++;
		}
		if (pos == word.length()) {
			return word;
		}
		StringBuffer sb = new StringBuffer();
		int tmp = pos;
		while (tmp >= 0) {
			sb.append(word.charAt(tmp--));
		}
		while (++pos < word.length()) {
			sb.append(word.charAt(pos));
		}
		return sb.toString();
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
